	function closeWindow() {
		window.close();
	}
	
	function CheckisNaN(value){
		var field=document.getElementById(value).value;
		
		if(field!=""&&isNaN(field)){
			alert("You must input number in this field");
			document.getElementById(value).value="";
		}

	}

	
	function CheckisInt(value){
		var field=document.getElementById(value).value;
		
		if(field!=""&&isNaN(field)){
			alert("You must input number in this field");
			document.getElementById(value).value="";
		}else if(!(field%1 === 0)){
			alert("You must input Integer in this field");
			document.getElementById(value).value="";
		}
	}
	
    function showTooltip(target) {  
 	    document.getElementById(target.id.replace(/^label/,'tooltip')).style.display = 'block';  
 	}  
 	function hideTooltip(target) {  
 	    document.getElementById(target.id.replace(/^label/,'tooltip')).style.display = 'none';  
 	} 
	
	function SetLeftRowID() {
		
		$("#functionID").html("<h3>f(x) function for "+right[request("result")]+"	</h3>");
		
		$("#fxFunctionForm").append("<input name=\"columnNum\" value=	\""+request("result")+"\"		type=\"hidden\"\>");
		
	}

	// created by Yuan Huang

	//for generating the table and add values
	function addtable() {

		var sendvalue = request("value");

		var values = sendvalue.split(',');

		$("#hiddenValueDiv")
				.html(
						"<input type=\"hidden\" name=\"sendValue\" value=\""+sendvalue+"\"   \>");

		$
				.each(
						values,
						function(key, value) {
							
							var headName=left[value-1];

							var tabletamplate = "<table class=\"table table-striped table-bordered StringTable\">	<tr><th>String</th><th>CheckBox</th><th>Char1</th><th>Char2</th></tr><tr>"
								+ " <td onmouseover='showTooltip(this);' onmouseout='hideTooltip(this);' id='label0'>InitCap</td><td align=\"center\"><input name=\"InitCap"+value+"\" id=\"InitCap"
								+value+"\" type=\"checkbox\"  /></td><td></td><td></td></tr><tr>"
									+ " <td onmouseover='showTooltip(this);' onmouseout='hideTooltip(this);' id='label1'>toUpperCase</td><td align=\"center\"><input name=\"checkBoxUpper"+value+"\" id=\"checkBoxUpper"
				+value+"\" type=\"checkbox\"  /></td><td></td><td></td></tr><tr>"
									+ "<td onmouseover='showTooltip(this);' onmouseout='hideTooltip(this);' id='label2'>toLowerCase</td><td align=\"center\"><input name=\"checkBoxLower"+value+"\" id=\"checkBoxLower"
				+value+"\" type=\"checkbox\"  /></td><td></td><td></td></tr><tr><td onmouseover='showTooltip(this);' onmouseout='hideTooltip(this);' id='label3'>Ltrim</td>"
									+ "<td align=\"center\"><input name=\"checkBoxLtrim"+value+"\" id=\"checkBoxLtrim"+value+"\" type=\"checkbox\"  /></td><td>"
									+ "</td><td></td></tr><tr><td onmouseover='showTooltip(this);' onmouseout='hideTooltip(this);' id='label4'>Rtrim</td><td align=\"center\"><input name=\"checkBoxRtrim"+value+"\" id=\"checkBoxRtrim"
				+value+"\" type=\"checkbox\"  /></td><td></td><td></td></tr><tr><td onmouseover='showTooltip(this);' onmouseout='hideTooltip(this);' id='label5'>Trim</td><td align=\"center\"><input name=\"checkBoxTrim"
				+value+"\" id=\"checkBoxTrim"+value+"\" type=\"checkbox\"  /></td><td></td><td></td></tr><tr><td onmouseover='showTooltip(this);' onmouseout='hideTooltip(this);' id='label6'>Replace</td><td></td>"
									+ "<td align=\"center\">OldValue<input name=\"replaceOldChar"
				+value+"\" id=\"replaceOldChar"+value+"\" type=\"text\"  /></td><td align=\"center\">NewValue<input name=\"replaceNewChar"
				+value+"\" id=\"replaceNewChar"+value+"\" type=\"text\"  /></td></tr><tr><td onmouseover='showTooltip(this);' onmouseout='hideTooltip(this);' id='label7'>SubString</td><td></td>"
									+ "<td align=\"center\">index<input name=\"indexSub"
				+value+"\" id=\"indexSub"+value+"\" type=\"text\"  onblur=\"CheckisNaN('indexSub"+value+"');\"/></td><td align=\"center\">length<input name=\"lengthSub"
				+value+"\" id=\"lengthSub"+value+"\" type=\"text\" onblur=\"CheckisNaN('lengthSub"+value+"');\"/></td></tr><tr><td onmouseover='showTooltip(this);' onmouseout='hideTooltip(this);' id='label8'>Lpad</td><td></td>"
									+ "<td align=\"center\">size<input name=\"sizeL"
				+value+"\" id=\"sizeL"+value+"\" type=\"text\"  onblur=\"CheckisNaN('sizeL"+value+"');\"/></td><td align=\"center\">padstr<input name=\"padstrL"
				+value+"\" id=\"padstrL"+value+"\" type=\"text\"  /></td></tr><tr><td onmouseover='showTooltip(this);' onmouseout='hideTooltip(this);' id='label9'>Rpad</td><td></td>"
									+ "<td align=\"center\">size<input name=\"sizeR"
				+value+"\" id=\"sizeR"+value+"\" type=\"text\"  onblur=\"CheckisNaN('sizeR"+value+"');\"/></td><td align=\"center\">padstr<input name=\"padstrR"
				+value+"\" id=\"padstrR"+value+"\" type=\"text\"  /></td></tr></table>";
                            
							var tabletamplateDate = "<table class=\"table table-striped table-bordered DateTable\">	<tr><th>Date</th><th>CheckBox</th><th>Day</th><th>Month</th><th>Year</th></tr><tr>"
								+ " <td onmouseover='showTooltip(this);' onmouseout='hideTooltip(this);' id='label10'>Current Date</td><td align=\"center\"><input name=\"checkBoxCurrentTime"+value+"\" id=\"checkBoxCurrentTime"
								+value+"\" type=\"checkbox\"  /></td><td></td><td></td><td></td></tr><tr><td onmouseover='showTooltip(this);' onmouseout='hideTooltip(this);' id='label11'>Add</td><td></td>"
									+ "<td align=\"center\"><input name=\"AddDay"
				+value+"\" id=\"AddDay"+value+"\" type=\"text\" onblur=\"CheckisInt('AddDay"+value+"');\" /></td><td align=\"center\"><input name=\"AddMonth"
				+value+"\" id=\"AddMonth"+value+"\" type=\"text\" onblur=\"CheckisInt('AddMonth"+value+"');\" /></td><td align=\"center\"><input name=\"AddYear"
				+value+"\" id=\"AddYear"+value+"\" type=\"text\" onblur=\"CheckisInt('AddYear"+value+"');\" /></td></tr><tr><td onmouseover='showTooltip(this);' onmouseout='hideTooltip(this);' id='label12'>Minus</td><td></td>"
									+ "<td align=\"center\"><input name=\"MinusDay"
				+value+"\" id=\"MinusDay"+value+"\" type=\"text\" onblur=\"CheckisInt('MinusDay"+value+"');\" /></td><td align=\"center\"><input name=\"MinusMonth"
				+value+"\" id=\"MinusMonth"+value+"\" type=\"text\" onblur=\"CheckisInt('MinusMonth"+value+"');\" /></td><td align=\"center\"><input name=\"MinusYear"
				+value+"\" id=\"MinusYear"+value+"\" type=\"text\" onblur=\"CheckisInt('MinusYear"+value+"');\" /></td></tr></table>";

							var tabletamplateNum = "<table class=\" table table-striped table-bordered NumberTable\">	<tr><th>Number</th><th onmouseover='showTooltip(this);' onmouseout='hideTooltip(this);' id='label13'>Add(+)</th><th onmouseover='showTooltip(this);' onmouseout='hideTooltip(this);' id='label14'>Minus(-)</th><th onmouseover='showTooltip(this);' onmouseout='hideTooltip(this);' id='label15'>Multiply(*)</th><th onmouseover='showTooltip(this);' onmouseout='hideTooltip(this);' id='label16'>Divide(/)</th><th onmouseover='showTooltip(this);' onmouseout='hideTooltip(this);' id='label17'>Mod(%)</th></tr><tr>"
								+ " <td></td><td align=\"center\"><input name=\"add"+value+"\" id=\"add"
				+value+"\" type=\"text\" onblur=\"CheckisNaN('add"+value+"');\" /></td><td align=\"center\"><input name=\"minus"+value+"\" id=\"minus"
				+value+"\" type=\"text\" onblur=\"CheckisNaN('minus"+value+"');\" /></td><td align=\"center\"><input name=\"multiply"+value+"\" id=\"multiply"
				+value+"\" type=\"text\" onblur=\"CheckisNaN('multiply"+value+"');\" /></td><td align=\"center\"><input name=\"divide"+value+"\" id=\"divide"
				+value+"\" type=\"text\" onblur=\"CheckisNaN('divide"+value+"');\" /></td><td align=\"center\"><input name=\"mod"+value+"\" id=\"mod"
				+value+"\" type=\"text\" onblur=\"CheckisNaN('mod"+value+"');\" /></td></tr><tr><th>Number</th><th onmouseover='showTooltip(this);' onmouseout='hideTooltip(this);' id='label18'>Round</th><th onmouseover='showTooltip(this);' onmouseout='hideTooltip(this);' id='label19'>Truncate</th></tr><tr><td>Length</td><td align=\"center\"><input name=\"roundLength"+value+"\" id=\"roundLength"
				+value+"\" type=\"text\" onblur=\"CheckisNaN('roundLength"+value+"');\" /></td><td align=\"center\"><input name=\"truncateLength"+value+"\" id=\"truncateLength"
				+value+"\" type=\"text\" onblur=\"CheckisNaN('truncateLength"+value+"');\" /></td></tr></table>";
	            
							$("#"+headName+"Content").append(tabletamplate);
                            
							$("#"+headName+"Content").append(tabletamplateDate);
							
							$("#"+headName+"Content").append(tabletamplateNum);
							
							
							var descriptionInitCap = "<div id='tooltip0' class='syntax'><p>with the first letter of each word in uppercase, all other letters in lowercase.</p></div>";
							var descriptionUpperCase = "<div id='tooltip1' class='syntax'><p>with all letters uppercase</p></div>";
							var descriptionLowerCase = "<div id='tooltip2' class='syntax'><p>with all letters lowercase</p></div>";
							var descriptionLtrim = "<div id='tooltip3' class='syntax'><p>removes from the left end of char all of the characters contained in string</p></div>";
							var descriptionRtrim = "<div id='tooltip4' class='syntax'><p>removes from the right end of char all of the characters that appear in string</p></div>";
							var descriptionTrim = "<div id='tooltip5' class='syntax'><p>enables you to trim leading or trailing characters (or both) from a character string</p></div>";
							var descriptionReplace = "<div id='tooltip6' class='syntax'><p>with every occurrence of old_value replaced with new_value. If new_value is omitted or null, then all occurrences of old_value are removed</p></div>";
							var descriptionSubstring = "<div id='tooltip7' class='syntax'><p>The SUBSTR functions return a portion of char, beginning at character position, substring_length characters long. SUBSTR calculates lengths using characters as defined by the input character set. </p></div>";
							var descriptionLpad = "<div id='tooltip8' class='syntax'><p>left-padded to length characters with the sequence of characters in padstr</p></div>";
							var descriptionRpad = "<div id='tooltip9' class='syntax'><p>right-padded to length n characters with the sequence of characters in padstr</p></div>";
							var descriptionCurrentTime = "<div id='tooltip10' class='syntax'><p>returns the current date and time set for the operating system</p></div>";
							var descriptionAddTime = "<div id='tooltip11' class='syntax'><p>returns the date date plus integer days/months/years</p></div>";
							var descriptionMinusTime = "<div id='tooltip12' class='syntax'><p>returns the date date minus integer days/months/years</p></div>";
							var descriptionAddNumber = "<div id='tooltip13' class='syntax'><p>descriptions Add Number</p></div>";
							var descriptionMinusNumber = "<div id='tooltip14' class='syntax'><p>descriptions Minus Number</p></div>";
							var descriptionMultiplyNumber = "<div id='tooltip15' class='syntax'><p>descriptions Multiply Number</p></div>";
							var descriptionDivideNumber = "<div id='tooltip16' class='syntax'><p>descriptions Divide Number</p></div>";
							var descriptionModNumber = "<div id='tooltip17' class='syntax'><p>returns the remainder of number divided by input</p></div>";
							var descriptionRound = "<div id='tooltip18' class='syntax'><p>returns number rounded to length places to the right of the decimal point. The argument length can be negative to round off digits left of the decimal point.</p></div>";
							var descriptionTruncate = "<div id='tooltip19' class='syntax'><p>returns nubmer truncated to length decimal places. The argument length can be negative to truncate (make zero) digits left of the decimal point</p></div>";
							
							$("#syntaxDescription").append(descriptionInitCap);
							$("#syntaxDescription").append(descriptionUpperCase);
							$("#syntaxDescription").append(descriptionLowerCase);
							$("#syntaxDescription").append(descriptionLtrim);
							$("#syntaxDescription").append(descriptionRtrim);
							$("#syntaxDescription").append(descriptionTrim);
							$("#syntaxDescription").append(descriptionReplace);
							$("#syntaxDescription").append(descriptionSubstring);
							$("#syntaxDescription").append(descriptionLpad);
							$("#syntaxDescription").append(descriptionRpad);
							$("#syntaxDescriptionDate").append(descriptionCurrentTime);
							$("#syntaxDescriptionDate").append(descriptionAddTime);
							$("#syntaxDescriptionDate").append(descriptionMinusTime);
							$("#syntaxDescriptionNum").append(descriptionAddNumber);
							$("#syntaxDescriptionNum").append(descriptionMinusNumber);
							$("#syntaxDescriptionNum").append(descriptionMultiplyNumber);
							$("#syntaxDescriptionNum").append(descriptionDivideNumber);
							$("#syntaxDescriptionNum").append(descriptionModNumber);
							$("#syntaxDescriptionNum").append(descriptionRound);
							$("#syntaxDescriptionNum").append(descriptionTruncate);
							
							$("#checkBoxUpper" + value).click(function() {

								if ($("#checkBoxLower" + value)[0].checked) {

									alert("please uncheck toLowerCase first");
									return false;
								}

							});

							$("#checkBoxLower" + value).click(function() {

								if ($("#checkBoxUpper" + value)[0].checked) {
									alert("please uncheck toLowerCase first");
									return false;
								}

							});

						});

	}
	
	
	function createHead()
	{
		
		var sendvalue = request("value");

		var values = sendvalue.split(',');
		
		$.each(values,function(key,value){
			var headName =  left[value-1]  ;

			$("#tableLink").append(" <li><a href='#"+headName+"Content' class='tab-head'>"+headName+"</a></li>");
			
		});
		
		$('.tab-head').click(function(){
			$(this).tab("show");
			
			$(".tab-pane").hide();
			$($(this).attr("href")).show();
		});
		
		
		$('.tab-head:first').tab("show");		
		
	}
	
	
	function createContentDiv()
	{
		var sendvalue = request("value");

		var values = sendvalue.split(',');
		
		$.each(values,function(key,value){
			var headName =  left[value-1]  ;

			$("#tableSets").append("<div class='tab-pane' id='"+headName+"Content'> </div>");
			
		});
		
		$(".tab-pane").hide();
		
		$(".tab-pane:first").show();
		
		
	}
	
	
	
	function handleSelect(){
		$("table").hide();
		
		$("#RadioTypeString").click(function(){
			
			$("table").hide();
			$(".StringTable").show();
			
			
		});
		
		$("#RadioTypeDate").click(function(){
			
			$("table").hide();
			$(".DateTable").show();
			
			
		});
		
		$("#RadioTypeNumber").click(function(){
			
			$("table").hide();
			$(".NumberTable").show();
			
			
		});
		
		
		
		$("#RadioTypeString").click();
		
		
		
	}
	

	$(function() {

		SetLeftRowID();
		
		createHead();
		createContentDiv();
		
		addtable();
		handleSelect();
		
	});